<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
	pageEncoding="ISO-8859-1"%>
<%@ page language="java" import="java.sql.*"%>
<%
	Class.forName("org.postgresql.Driver");
	Connection conn = DriverManager.getConnection(
		"jdbc:postgresql://localhost:5432/cse132b", "cse132blogin",
		"1234567890");
	Statement stmt;
	
	stmt = conn.createStatement();
	ResultSet rs = stmt.executeQuery("SELECT distinct students.* FROM students, ms, enroll, classes WHERE students.student_id = ms.student_id AND students.student_id = enroll.student_id AND classes.class_id = enroll.section_id AND quarter = '2' and year = 2014;");

	String HTML = "";
	while (rs.next()) {
	
		HTML += "<tr>";
		HTML += "	<td><a href=javascript:doSomething(" + rs.getInt("student_id") + ");>" + rs.getString("ssn") + "</a></td>";
		HTML += "	<td>" + rs.getString("first_name") + "</td>";
		HTML += "	<td>" + rs.getString("middle_name") + "</td>";
		HTML += "	<td>" + rs.getString("last_name") + "</td>";
	}
	rs.close();
	stmt.close();
	
%>
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">
	function doSomething(s) {
		myControl = document.getElementById("sltDegrees");
		window.location.href = "report1eii.jsp?ID=" + s.toString() + "&degrees=" + myControl.options[myControl.selectedIndex].value;
	
	}
</script>
</head>
<body>
	<table border="1">
		<tr>
			<td valign="top" width="30%">
				<%-- -------- Include menu HTML code -------- --%> <jsp:include
					page="/menu.html" />
			</td>
			<td>
			<p align="center">
					<font size="6">Display the classes currently taken by MS student</font>
				</p>
				<table border="1">

						<tr>
							<td colspans=4><select name="sltDegrees" id="sltDegrees">
									<%
										stmt = conn.createStatement();
										ResultSet rsDegrees = stmt
												.executeQuery("SELECT * FROM degrees_offered WHERE type_degree = 'MS'");
	
										while (rsDegrees.next()) {
												
									%>
									<option value="<%=rsDegrees.getInt("degrees_id")%>"><%=rsDegrees.getString("name")%></option>
									<%
										
											}
											rsDegrees.close();
											stmt.close();
									%>
							</select></td>
							</tr>
					<tr>
						<th>SSN</th>
						<th>First Name</th>
						<th>Middle Name</th>
						<th>Last Name</th>
					</tr>
					<%=HTML%>
				</table>

			</td>
		</tr>
	</table>
</body>
<%
	// Close the Connection
	conn.close();
%>